﻿using Microsoft.AspNetCore.Mvc;
using S8_ISservice;
using S8_Service;
using S8_UI.Models;
using System.Diagnostics;

namespace S8_UI.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IUserService _userService;

        public HomeController(ILogger<HomeController> logger,IUserService userService)
        {
            _logger = logger;
            _userService = userService;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public IActionResult Index([FromQuery]IndexArgs args)
        {
            //UserService service = new UserService();

            var list = _userService.GetList();
            //this.ViewData["list"] = list;
            //return View();
            return Json(list.Select(t=>new
            {
                 Name=t.Name,
                 Id=t.Id,
                 Gender=t.Gender,
                 Age=t.Age,
            }).ToList());
        }
        //public class ResponseUser
        //{
        //    public string Id { get;set; }
        //    public string Name { get; set; }
        //    public int? Gender { get; set; }
        //    public int? Age { get; set; }
        //}
        /// <summary>
        /// 参数模型
        /// </summary>
        public class IndexArgs
        {
            public int? Page { get; set; }
            public string? SearchKey { get; set; }
            public int? Status { get; set; }
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
